﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecommerce.Model;

namespace Ecommerce.Admin.Paginas
{
    public partial class AdicionarRevenda : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["IdRev"] != null)
                {
                    hddIdentificador.Value = Request.QueryString["IdRev"];
                    //ObterRevenda();
                }
            }
        }

        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            RevendaModel model = new RevendaModel();

            var pes = new tb_pes_pessoa();
            pes.pes_dat_criacao = DateTime.Now;
            pes.pes_flg_ativo = true;

            var pju = new tb_pju_pessoa_juridica();
            pju.pju_des_razao_social = txtRazaoSocial.Text;
            pju.pju_des_nom_fantasia = txtNomeFantasia.Text;
            pju.pju_end_website = txtWebSite.Text;
            pju.pju_num_cnpj = txtCNPJ.Text;
            pju.pju_num_inscricao_estadual = txtInscricaoEstadual.Text;
            
            var rev = new tb_rev_revenda();
            rev.rev_cod_revenda = txtCodigo.Text;

            pes.tb_pju_pessoa_juridica = pju;
            pes.tb_pju_pessoa_juridica.tb_rev_revenda = rev;

            model.Inserir(pes);

            Response.Redirect("GerenciarRevenda.aspx");
        }
    }
}